﻿using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;

namespace Eswat.Services.WebDriver
{
	/// <summary>
	/// Represents a type of web browser.
	/// </summary>
	public class WebBrowserType
	{
		/// <summary>
		/// Factory method for creating a corresponding web driver.
		/// </summary>
		private readonly Func<IWebDriver> _webDriverFactory;

		/// <summary>
		/// Singleton Internet Explorer browser type.
		/// </summary>
		public static WebBrowserType IE = new WebBrowserType("Microsoft Internet Explorer", () => new InternetExplorerDriver());

		/// <summary>
		/// Singleton Chrome browser type.
		/// </summary>
		public static WebBrowserType Chrome = new WebBrowserType("Google Chrome", () => new ChromeDriver());

		/// <summary>
		/// Singleton Firefox browser type.
		/// </summary>
		public static WebBrowserType Firefox = new WebBrowserType("Mozilla Firefox", () => new FirefoxDriver());

		/// <summary>
		/// Initializes a new instance of the <see cref="WebBrowserType"/> class.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <param name="webDriverFactory">The web driver factory method.</param>
		public WebBrowserType(string name, Func<IWebDriver> webDriverFactory)
		{
			this._webDriverFactory = webDriverFactory;
			this.Name = name;
		}

		/// <summary>
		/// Gets the name.
		/// </summary>
		public string Name { get; private set; }

		/// <summary>
		/// Creates an instance of a web driver that corresponds to this web browser type.
		/// </summary>
		/// <returns></returns>
		public IWebDriver Create()
		{
			var webDriver = this._webDriverFactory();

			return webDriver;
		}
	}
}
